(function () { // ============================================================ // 1. CONFIGURATION — Edit here freely // ============================================================ const navData = [ { title: "Portfolio", subLinks: [ { label: "Weddings", icon: "", micon: "" }, { label: "Portraits", icon: "", micon: "" }, { label: "Landscapes", icon: "", micon: "" }, { label: "Commercial", icon: "", micon: "" } ] }, { title: "Gallery", subLinks: [ { label: "Curated Gallery", icon: "", micon: "" }, { label: "General Gallery", icon: "", micon: "" }, { label: "Upload", icon: "", micon: "" } ] }, { title: "Services", subLinks: [ { label: "Photography", icon: "", micon: "" }, { label: "Videography", icon: "", micon: "" }, { label: "Editing", icon: "", micon: "" }, { label: "Workshops", icon: "", micon: "" } ] }, { title: "About", subLinks: [ { label: "Our Story", icon: "", micon: "" }, { label: "The Team", icon: "", micon: "" }, { label: "Contact Us", icon: "", micon: "" } ] } ]; const logos = { light: "https://pub-59fb7bdcb1b041a180d5501daa37d347.r2.dev/Website%20Important%20Images/PZ_Logo.png", dark: "https://pub-59fb7bdcb1b041a180d5501daa37d347.r2.dev/Website%20Important%20Images/PhotoZone_Logo-darken.png" }; // ============================================================ // 2. CSS // ============================================================ const css = ` :root { --pz-h: 64px; --pz-ease: cubic-bezier(0.22, 1, 0.36, 1); --pz-fast: 0.18s ease; --pz-smooth: 0.35s var(--pz-ease); /* ── NAV TRANSPARENCY ────────────────────────────────── Controls how visible the navbar background is. Range: 0.0 (fully invisible) → 1.0 (fully opaque) Light pages use white, dark pages use black — same alpha. Blur: increase for more frosted-glass effect. ── */ --pz-nav-alpha: 0.18; /* adjust this value */ --pz-nav-blur: 8px; /* adjust this value */ } /* ---- Base header ---- */ .pz-header { position: fixed; top: 0; left: 0; width: 100%; z-index: 9999; height: var(--pz-h); transition: background var(--pz-smooth), border-color var(--pz-smooth), backdrop-filter var(--pz-smooth); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif; border-bottom: 1px solid transparent; } /* Navbar background — controlled by --pz-nav-alpha and --pz-nav-blur above */ .pz-header.theme-light { background: rgba(255,255,255,var(--pz-nav-alpha)) !important; backdrop-filter: blur(var(--pz-nav-blur)); -webkit-backdrop-filter: blur(var(--pz-nav-blur)); border-bottom-color: rgba(0,0,0,0.06) !important; } .pz-header.theme-dark { background: rgba(0,0,0,var(--pz-nav-alpha)) !important; backdrop-filter: blur(var(--pz-nav-blur)); -webkit-backdrop-filter: blur(var(--pz-nav-blur)); border-bottom-color: rgba(255,255,255,0.06) !important; } /* ---- Container ---- */ .pz-nav-container { max-width: 1340px; margin: 0 auto; padding: 0 3rem; height: var(--pz-h); display: flex; align-items: center; justify-content: space-between; position: relative; } /* ---- Logo ---- */ .pz-logo { display: flex; align-items: center; text-decoration: none; flex-shrink: 0; } .pz-logo-wrap { position: relative; display: flex; align-items: center; } .pz-logo-img { height: 28px; width: auto; display: block; transition: opacity 0.3s ease; } .pz-logo-img.pz-logo-dark { position: absolute; left: 0; top: 50%; transform: translateY(-50%); } .pz-logo-img.pz-logo-light { opacity: 1; } .pz-logo-img.pz-logo-dark { opacity: 0; } .pz-header.theme-dark .pz-logo-img.pz-logo-light { opacity: 0; } .pz-header.theme-dark .pz-logo-img.pz-logo-dark { opacity: 1; } /* ---- Desktop Nav ---- */ .pz-nav-main { display: flex; align-items: center; gap: 0.25rem; height: var(--pz-h); position: relative; } .pz-nav-item { display: flex; align-items: center; height: var(--pz-h); } .pz-main-link { text-decoration: none; font-size: 0.8rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; padding: 0 1rem; height: 100%; display: flex; align-items: center; cursor: pointer; white-space: nowrap; transition: color var(--pz-fast); position: relative; } /* Animated underline pip */ .pz-main-link::after { content: ''; position: absolute; bottom: 14px; left: 50%; width: 0; height: 2px; border-radius: 2px; transform: translateX(-50%); transition: width var(--pz-smooth); } /* Light theme text */ .pz-header.theme-light .pz-main-link { color: #111; } .pz-header.theme-light .pz-main-link::after { background: #111; } .pz-header.theme-light .pz-main-link:hover { color: #000; } /* Dark theme text */ .pz-header.theme-dark .pz-main-link { color: rgba(255,255,255,0.88); } .pz-header.theme-dark .pz-main-link::after { background: #fff; } .pz-header.theme-dark .pz-main-link:hover { color: #fff; } /* Active link pip */ .pz-nav-item.pz-open .pz-main-link::after, .pz-nav-item:hover .pz-main-link::after { width: 20px; } /* ---- MEGA PANEL — single panel, all columns, right-anchored ---- */ .pz-mega-panel { position: absolute; top: calc(var(--pz-h) + 6px); right: 0; left: auto; display: flex; gap: 0; width: max-content; background: rgba(255,255,255,0.97); backdrop-filter: blur(20px) saturate(1.5); -webkit-backdrop-filter: blur(20px) saturate(1.5); border: 1px solid rgba(0,0,0,0.07); border-radius: 14px; box-shadow: 0 8px 40px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06); opacity: 0; visibility: hidden; pointer-events: none; transform: translateY(-8px); transition: opacity var(--pz-smooth), transform var(--pz-smooth), visibility var(--pz-smooth); } .pz-mega-panel::before { content: ''; position: absolute; top: -10px; left: 0; width: 100%; height: 14px; } .pz-nav-main:hover .pz-mega-panel, .pz-mega-panel:hover { opacity: 1; visibility: visible; pointer-events: auto; transform: translateY(0); } .pz-mega-col { padding: 1.4rem 1.5rem; min-width: 0; width: max-content; border-right: 1px solid rgba(0,0,0,0.055); } .pz-mega-col:last-child { border-right: none; } .pz-mega-col-title { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: #b0b0b0; margin-bottom: 0.9rem; padding-bottom: 0.6rem; border-bottom: 1px solid rgba(0,0,0,0.06); } .pz-mega-link { display: flex; align-items: center; gap: 9px; padding: 0.42rem 0.55rem; text-decoration: none; border-radius: 7px; transition: background var(--pz-fast), transform 0.2s var(--pz-ease); margin-bottom: 1px; } .pz-mega-link:hover { background: rgba(0,0,0,0.04); transform: translateX(3px); } .pz-mega-link svg { color: #999; transition: color var(--pz-fast); } .pz-mega-link:hover svg { color: #111; } .pz-mega-label { font-size: 0.84rem; font-weight: 500; color: #222; white-space: nowrap; } .pz-mega-link:hover .pz-mega-label { color: #000; } /* ---- Hamburger ---- */ .pz-hamburger { display: none; flex-direction: column; justify-content: center; gap: 5px; background: none; border: none; cursor: pointer; padding: 8px; z-index: 10001; flex-shrink: 0; } .pz-hamburger span { display: block; height: 1.5px; border-radius: 2px; transition: transform var(--pz-smooth), opacity 0.2s ease, width var(--pz-smooth); } .pz-hamburger span:nth-child(1) { width: 22px; } .pz-hamburger span:nth-child(2) { width: 16px; } .pz-hamburger span:nth-child(3) { width: 22px; } .pz-header.theme-light .pz-hamburger span { background: #111; } .pz-header.theme-dark .pz-hamburger span { background: #fff; } .pz-hamburger.pz-active span:nth-child(1) { transform: translateY(6.5px) rotate(45deg); width: 22px; } .pz-hamburger.pz-active span:nth-child(2) { opacity: 0; width: 0; } .pz-hamburger.pz-active span:nth-child(3) { transform: translateY(-6.5px) rotate(-45deg); width: 22px; } /* ── MOBILE ─────────────────────────────────────────────── */ @media (max-width: 991px) { .pz-hamburger { display: flex; } .pz-nav-main { display: none; } /* Backdrop */ .pz-mobile-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); z-index: 9998; opacity: 0; pointer-events: none; transition: opacity 0.35s ease; } .pz-mobile-overlay.pz-active { opacity: 1; pointer-events: auto; } /* Full-height drawer from right */ .pz-mobile-drawer { position: fixed; top: 0; right: -100%; width: min(300px, 84vw); height: 100dvh; background: #111; z-index: 9999; transition: right 0.4s var(--pz-ease); display: flex; flex-direction: column; box-shadow: -20px 0 60px rgba(0,0,0,0.5); } .pz-mobile-drawer.pz-active { right: 0; } /* Top: logo + close button */ .pz-mob-header { display: flex; align-items: center; justify-content: space-between; padding: 0 1.5rem; height: 64px; flex-shrink: 0; border-bottom: 1px solid rgba(255,255,255,0.07); } .pz-mob-header img { height: 24px; width: auto; } .pz-mob-close { width: 34px; height: 34px; border-radius: 8px; background: rgba(255,255,255,0.08); border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #fff; transition: background var(--pz-fast); } .pz-mob-close:hover { background: rgba(255,255,255,0.15); } /* Scrollable nav */ .pz-mob-nav { flex: 1; overflow-y: auto; padding: 1rem 0; } .pz-mob-nav::-webkit-scrollbar { width: 3px; } .pz-mob-nav::-webkit-scrollbar-track { background: transparent; } .pz-mob-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; } /* Section */ .pz-mobile-section { margin: 0 0.75rem 0.25rem; border-radius: 12px; overflow: hidden; } .pz-mobile-section-title { display: flex; align-items: center; justify-content: space-between; padding: 0.85rem 1rem; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: rgba(255,255,255,0.5); cursor: pointer; user-select: none; transition: color var(--pz-fast), background var(--pz-fast); border-radius: 10px; } .pz-mobile-section-title:hover { color: #fff; background: rgba(255,255,255,0.05); } .pz-mobile-section.pz-open .pz-mobile-section-title { color: #fff; } /* Chevron SVG */ .pz-mobile-chevron { width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; transition: transform 0.28s var(--pz-ease); flex-shrink: 0; } .pz-mobile-section.pz-open .pz-mobile-chevron { transform: rotate(180deg); } /* Sub-links panel */ .pz-mobile-links { max-height: 0; overflow: hidden; transition: max-height 0.35s var(--pz-ease); } .pz-mobile-section.pz-open .pz-mobile-links { max-height: 500px; } .pz-mobile-link { display: flex; align-items: center; gap: 10px; padding: 0.7rem 1rem 0.7rem 1.2rem; margin: 1px 0.5rem; font-size: 0.88rem; font-weight: 400; color: rgba(255,255,255,0.45); text-decoration: none; border-radius: 8px; transition: color var(--pz-fast), background var(--pz-fast); white-space: nowrap; } .pz-mobile-link svg { opacity: 0.5; flex-shrink: 0; transition: opacity var(--pz-fast); } .pz-mobile-link:hover { color: #fff; background: rgba(255,255,255,0.06); } .pz-mobile-link:hover svg { opacity: 1; } /* Footer: social icons */ .pz-mob-footer { flex-shrink: 0; padding: 1rem 1.5rem; border-top: 1px solid rgba(255,255,255,0.07); display: flex; align-items: center; gap: 4px; } .pz-mob-footer-label { font-size: 0.65rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: rgba(255,255,255,0.25); margin-right: auto; } .pz-mob-social { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 9px; background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.45); text-decoration: none; transition: background var(--pz-fast), color var(--pz-fast); } .pz-mob-social:hover { background: rgba(255,255,255,0.14); color: #fff; } .pz-mob-social svg { display: block; } } `; // ============================================================ // 3. HTML STRUCTURE // ============================================================ const megaCols = navData.map(item => `
${item.title}
${item.subLinks.map(sub => ` ${sub.icon} ${sub.label} `).join('')}
`).join(''); const desktopNavHTML = navData.map(item => `
${item.title}
`).join('') + `
${megaCols}
`; const mobSections = navData.map(item => `
${item.title}
`).join(''); const mobileDrawerHTML = `
PhotoZone Graphy
${mobSections}
`; const headerHTML = `
`; // ============================================================ // 4. INJECT // ============================================================ const initNavbar = () => { // Inject styles const style = document.createElement('style'); style.textContent = css; document.head.appendChild(style); // Google Font // Header element const header = document.createElement('header'); header.className = 'pz-header theme-light'; header.innerHTML = headerHTML; document.body.prepend(header); // Spacer so page content doesn't hide under fixed nav const spacer = document.createElement('div'); spacer.style.cssText = `height: 64px; display: block;`; document.body.insertBefore(spacer, header.nextSibling); // Mobile overlay + drawer const overlay = document.createElement('div'); overlay.className = 'pz-mobile-overlay'; document.body.appendChild(overlay); const drawer = document.createElement('div'); drawer.className = 'pz-mobile-drawer'; drawer.innerHTML = mobileDrawerHTML; document.body.appendChild(drawer); // ============================================================ // 5. SECTION-AWARE COLOR DETECTION // ============================================================ /** * Sample a small horizontal strip at Y = navHeight/2 of the * visible area to determine the luminance of what's behind the navbar. * Strategy: Collect all elements whose bounding box overlaps * the navbar's centre-line, read their computed background-color, * blend them top-to-bottom and compute relative luminance. */ let currentTheme = 'light'; const getLuminance = (r, g, b) => { const sRGB = [r, g, b].map(v => { v /= 255; return v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4); }); return 0.2126 * sRGB[0] + 0.7152 * sRGB[1] + 0.0722 * sRGB[2]; }; const parseColor = (colorStr) => { if (!colorStr || colorStr === 'transparent' || colorStr === 'rgba(0, 0, 0, 0)') return null; const m = colorStr.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/); if (!m) return null; const alpha = m[4] !== undefined ? parseFloat(m[4]) : 1; if (alpha < 0.05) return null; // nearly transparent — skip return { r: +m[1], g: +m[2], b: +m[3], a: alpha }; }; const blendOnWhite = (colors) => { // Composite color list (front to back) onto white let r = 255, g = 255, b = 255; for (let i = colors.length - 1; i >= 0; i--) { const c = colors[i]; const a = c.a; r = c.r * a + r * (1 - a); g = c.g * a + g * (1 - a); b = c.b * a + b * (1 - a); } return { r, g, b }; }; const detectTheme = () => { const navH = parseInt(getComputedStyle(header).height) || 64; const sampleY = window.scrollY + navH * 0.5; // Walk the DOM and collect elements whose bbox vertically overlaps sampleY const all = document.body.querySelectorAll('*'); const colors = []; for (let el of all) { // Skip the navbar itself if (header.contains(el) || el === header) continue; if (el === spacer || el === overlay || el === drawer) continue; const rect = el.getBoundingClientRect(); const absTop = rect.top + window.scrollY; const absBottom = rect.bottom + window.scrollY; // Must straddle the sample line if (absTop > sampleY || absBottom < sampleY) continue; // Must span the full width (rough heuristic for section-level elements) if (rect.width < window.innerWidth * 0.4) continue; const bg = window.getComputedStyle(el).backgroundColor; const parsed = parseColor(bg); if (parsed) colors.push(parsed); } let lum; if (colors.length === 0) { // Fallback: check body const bodyBg = parseColor(window.getComputedStyle(document.body).backgroundColor); lum = bodyBg ? getLuminance(bodyBg.r, bodyBg.g, bodyBg.b) : 1; } else { const blended = blendOnWhite(colors); lum = getLuminance(blended.r, blended.g, blended.b); } // Luminance threshold: >0.35 = light background, ≤0.35 = dark background const newTheme = lum > 0.35 ? 'light' : 'dark'; if (newTheme !== currentTheme) { currentTheme = newTheme; header.classList.remove('theme-light', 'theme-dark'); header.classList.add(`theme-${newTheme}`); } }; // Run detection frequently but efficiently let ticking = false; const onScroll = () => { if (!ticking) { requestAnimationFrame(() => { detectTheme(); // Scrolled glass effect if (window.scrollY > 10) { header.classList.add('pz-scrolled'); } else { header.classList.remove('pz-scrolled'); } ticking = false; }); ticking = true; } }; window.addEventListener('scroll', onScroll, { passive: true }); detectTheme(); // Initial run // Re-detect after images / fonts load (they may affect section heights) window.addEventListener('load', detectTheme); // Mega panel is CSS :hover driven — no JS needed for desktop open/close // Close on outside click (accessibility) document.addEventListener('click', (e) => { if (!header.contains(e.target)) { header.querySelectorAll('.pz-nav-item').forEach(i => i.classList.remove('pz-open')); } }); // ============================================================ // 7. MOBILE MENU // ============================================================ const hamburger = header.querySelector('.pz-hamburger'); const closeMobile = () => { hamburger.classList.remove('pz-active'); hamburger.setAttribute('aria-expanded', 'false'); overlay.classList.remove('pz-active'); drawer.classList.remove('pz-active'); document.body.style.overflow = ''; }; hamburger.addEventListener('click', () => { const isOpen = drawer.classList.contains('pz-active'); if (isOpen) { closeMobile(); } else { hamburger.classList.add('pz-active'); hamburger.setAttribute('aria-expanded', 'true'); overlay.classList.add('pz-active'); drawer.classList.add('pz-active'); document.body.style.overflow = 'hidden'; } }); overlay.addEventListener('click', closeMobile); // Close button inside drawer const mobCloseBtn = drawer.querySelector('#pzMobClose'); if (mobCloseBtn) mobCloseBtn.addEventListener('click', closeMobile); // Accordion in drawer const mobileSections = drawer.querySelectorAll('.pz-mobile-section'); mobileSections.forEach(section => { const title = section.querySelector('.pz-mobile-section-title'); title.addEventListener('click', () => { const isOpen = section.classList.contains('pz-open'); mobileSections.forEach(s => s.classList.remove('pz-open')); if (!isOpen) section.classList.add('pz-open'); }); }); window.addEventListener('resize', () => { if (window.innerWidth >= 992) closeMobile(); }); // Close mobile on link click drawer.querySelectorAll('.pz-mobile-link').forEach(link => { link.addEventListener('click', closeMobile); }); }; // ============================================================ // 8. BOOT // ============================================================ if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initNavbar); } else { initNavbar(); } })();